package com.plant.serviceImpl;

import java.util.List;

import com.plant.dao.BaseDao;
import com.plant.entity.PgcAdmin;
import com.plant.entity.PgcUploadImages;
import com.plant.entity.PgcVirtualUser;
import com.plant.entity.UgcUser;
import com.plant.service.AdminRegisterService;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author 植物先生-李琦
 * 
 * 			---下面是注册接口
 */
@Service  //依赖注册 必须写注册 下面在写resource资源
@Transactional
public class AdminRegisterServiceImpl implements AdminRegisterService{
    @Resource(name = "baseDaoImpl")      //注解扫描basedao接口方法
    private BaseDao baseDao;
    


	public PgcAdmin checkUser(PgcAdmin admin) {//---1.管理员登录验证
		String hql = " from PgcAdmin where username = :username and password = :password";
		PgcAdmin a = null;
		@SuppressWarnings("rawtypes")
		List list = baseDao.findname(hql, new String[]{"username","password"}, new Object[]{admin.getUsername(), admin.getPassword()});
		if (list!=null&&list.size()>0) {
			a = (PgcAdmin) list.get(0);
		}
		return a;
	}

	@SuppressWarnings("unchecked")
	public List<Object[]> virtualuser(PgcAdmin admin,Integer page,String time) {
		String hql="select a.user_id,b.nickname,b.photo from pgc_virtual_user as a,ugc_user as b where b.id=a.user_id and a.from_admin_id=("+admin.getId()+") and b.register_time<? order by b.register_time desc";
		return baseDao.findfenye((page-1)*20, 20, hql, time, PgcAdmin.class);
	}

	public boolean addvirtualuser(UgcUser user) {	//用户添加马甲
		boolean isadd=true; 
		isadd=baseDao.add(user);
		return isadd;
	}
	public boolean upvirtualuser(UgcUser user) {	//修改马甲用户
		boolean isadd=true; 
		isadd=baseDao.update(user);
		return isadd;
	}
	public boolean addvirtual(PgcVirtualUser viuser) {	//添加到马甲关系表
		boolean isadd=true; 
		isadd=baseDao.add(viuser);
		return isadd;
	}
    public List<Object> getByuid(UgcUser uf) {         //--2通过用户id查找单个马甲用户信息
        String hql="from UgcUser ug where ug.id=?";
        return baseDao.find(hql, uf.getId());
    }

	public boolean pcupload(PgcUploadImages pu) {
		boolean isadd=true; 
		isadd=baseDao.add(pu);
		return isadd;
	}

	@SuppressWarnings("unchecked")
	public List<Object> pcphoto(PgcAdmin admin, Integer page, String time) {//---查看显示pc端图片
		String hql="select url from pgc_upload_images where admin_id=("+admin.getId()+") and create_time<? order by create_time desc";
		return baseDao.findfenye((page-1)*20, 20, hql, time, null);
	}

	public Long pcphotocount(PgcUploadImages pa) { //----统计pc上传图片条数
		String hql="select count(id) from PgcUploadImages where adminId=("+pa.getAdminId()+")";
		Long lo=baseDao.CountHql(hql);
		return lo;
	}

	public Long vittualcount(PgcAdmin admin) {//-----查看统计马甲用户的个数
		String hql="select count(id) from PgcVirtualUser where fromAdminId=("+admin.getId()+")";
		Long lo=baseDao.CountHql(hql);
		return lo;
	}

	public boolean delvirtual(UgcUser user) {     //---Pc端删除马甲用户
		boolean b=true;
		String hql="delete from UgcUser where id=("+user.getId()+")";
		b=baseDao.updatehql(hql);
		String hql1="delete from PgcVirtualUser where userId=("+user.getId()+")";
		b=baseDao.updatehql(hql1);
		return b;
	}
	
	
 }
